{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
.file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
.file-item .info{overflow: hidden;}
.uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加等级分润规则</h5>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="edit" id="signupForm" method="post">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">我的等级：</label>
                            <div class="input-group col-sm-4">
                                <select name="first_level" id="first_level" class="form-control" onchange="changeLevel('first_level', 'firstLevel')">
                                    <option value="">-请选择我的等级-</option>
                                    <option value="1">店长</option>
                                    <option value="2">超级店长</option>
                                    <option value="3">总代理</option>
                                </select>
                            </div>
                        </div>


                        <div class="form-group" id="firstLevel" style="display:none;">
                            <label class="col-sm-3 control-label">我的比例：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" name="first_rate" class="form-control">
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">上家的等级：</label>
                            <div class="input-group col-sm-4">
                                <select name="second_level" id="second_level" class="form-control" onchange="changeLevel('second_level', 'secondLevel')">
                                    <option value="">-请选择我的等级-</option>
                                    <option value="1">店长</option>
                                    <option value="2">超级店长</option>
                                    <option value="3">总代理</option>
                                </select>
                            </div>
                        </div>


                        <div class="form-group" id="secondLevel" style="display:none;">
                            <label class="col-sm-3 control-label">上家的比例：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" name="second_rate" class="form-control">
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">上上家的等级：</label>
                            <div class="input-group col-sm-4">
                                <select name="third_level" id="third_level" class="form-control" onchange="changeLevel('third_level', 'thirdLevel')">
                                    <option value="">-请选择我的等级-</option>
                                    <option value="1">店长</option>
                                    <option value="2">超级店长</option>
                                    <option value="3">总代理</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group" id="thirdLevel" style="display:none;">
                            <label class="col-sm-3 control-label">上上的比例：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" name="third_rate" class="form-control">
                            </div>
                            <div class="hr-line-dashed"></div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button id="formSubmit" type="submit" class="btn btn-primary"><i class="fa fa-check"></i> 提交</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>
<script type="text/javascript" src="/static/admin/js/common.js"></script>
<script type="text/javascript">

function changeLevel(inputName, divName) {
    inputName = $("#"+inputName).val();

    if (!common.isNullOrEmpty(inputName)) {
        $("#"+divName).show();
    } else {
        $("#"+divName).hide();
    }

}

    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({
     
        auto: true,// 选完文件后，是否自动上传。   
        swf: '/static/admin/webupload/Uploader.swf',// swf文件路径 
        server: "{:url('Upload/uploadFace')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/uploads/face/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
        $list.html( '<div id="' + file.id + '" class="item">' +
            '<h4 class="info">' + file.name + '</h4>' +
            '<p class="state">正在上传...</p>' +
        '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });

    //以下为官方示例
    $().ready(function () {

        // validate signup form on keyup and submit
        var icon = "<i class='fa fa-times-circle'></i> ";
        $("#signupForm").validate({
            rules: {
                first_level: {
                    required: true,
                },
                first_rate: {
                    required: true,
                    number:true
                },
                second_rate: {
                    required: true,
                    number:true
                },
                third_rate: {
                    required: true,
                    number:true
                },
            },
            focusCleanup:true,
            submitHandler:function(form){

                $(form).ajaxSubmit({
                    type: 'post',
                    url: "{:url('addPost')}",
                    beforeSend:function() {
                        // 显示loading
                        index2 = layer.load(0, {
                            shade: [0.3,'#fff']
                        });
                        $("#formSubmit").attr('type', 'button')
                    },
                    success: function(data){

                        if (data['code'] != 1) {
                            layer.msg(data.msg,{icon:2,time:1000,shade: 0.1,}, function(index){
                                layer.close(index)
                            });
                            $("#formSubmit").attr('type', 'submit')
                            return false;
                        }

                        layer.msg(data.msg,{icon:1,time:1000,shade: 0.1,}, function(index){
                            window.location.href="{:url('index')}"
                        });
                    },
                    error: function(XmlHttpRequest, textStatus, errorThrown){
                        layer.msg('error!',{icon:1,time:1000});
                    },
                    complete:function() {
                        // 隐藏loading
                        layer.close(index2);
                    }
                });
            }
        });
    });

</script>
</body>
</html>